from flask_login import login_required

from ..base import base
from ..service.IndustryInformationService import *
from flask import request

from exts import success, page_success


@base.route('/api/industry/information/add', methods=['POST'])
@login_required
def industry_information_add_api():
    '''
    添加资讯信息
    :return:
    '''
    industry_information = request.get_json()
    industry_information_add(industry_information)
    return success(industry_information)


@base.route('/api/industry/information/update', methods=['POST'])
@login_required
def industry_information_update_api():
    '''
    更新资讯信息
    :return:
    '''
    industry_information = request.get_json()
    industry_information_update(industry_information)
    return success(industry_information)


@base.route('/api/industry/information/delete', methods=['POST'])
@login_required
def industry_information_delete_api():
    '''
    删除资讯信息
    :return:
    '''
    customer_message = request.get_json()
    industry_information_delete(customer_message['id'])
    return success(customer_message['id'])


@base.route('/api/industry/information/detail', methods=['POST'])
@login_required
def industry_information_detail_api():
    '''
    查询资讯信息
    :return:
    '''
    customer_message = request.get_json()
    return success(industry_information_get_by_id(customer_message['id']))


@base.route('/api/industry/information/page', methods=['POST'])
@login_required
def industry_information_page_api():
    '''
    分页查询资讯
    :return:
    '''
    customer_message = request.get_json()
    page = industry_information_page(customer_message['pageNum'], customer_message['pageSize'])
    return page_success(page.total, page.items)


# ===================================pc web端api接口====================================================
@base.route('/api/industry/information/all', methods=['GET'])
def industry_information_all_api():
    '''
    查询资讯信息 web pc端
    :return:
    '''
    return success(industry_information_all())
